Applications often use static controls to label other controls or to separate a group of controls. Although static controls are child windows, they cannot be selected. Therefore, they cannot receive the keyboard focus and cannot have a keyboard interface. A static control that has the SS_NOTIFY style receives mouse input, notifying the parent window when the user clicks or double clicks the control. Static controls belong to the STATIC window class.
Although static controls can be used in overlapped, pop-up, and child windows, they are designed for use in dialog boxes, where the system standardizes their behavior. By using static controls outside dialog boxes, a developer increases the risk that the application might behave in a nonstandard fashion. Typically, a developer either uses static controls in dialog boxes or uses the SS_OWNERDRAW style to create customized static controls.
Include file: CStatic.inc.
| Name | Description |
|---|---|
| DeleteBitmap | Deletes a bitmap associated with a static control. |
| DeleteCursor | Deletes a cursor associated with a static control. |
| DeleteEnhancedMetafile | Deletes an enhanced metafile associated with a static control. |
| DeleteIcon | Deletes an icon associated with a static control. |
| DeleteImage | Deletes an image associated with a static control. |
| Disable | Disables the control. |
| Enable | Enables the control. |
| GetIcon | Retrieves a handle to the icon associated with a static control that has the SS_ICON style. |
| GetImage | Retrieves a handle to the image (icon or bitmap) associated with a static control. |
| GetText | Gets the text of a static control. |
| GetTextLength | Gets the length of the text of a static control. |
| SetBitmap | Associates a bitmap with a static control. |
| SetCursor | Associates a cursor with a static control. |
| SetEnhancedMetafile | Associates an enhanced metafile with a static control. |
| SetIcon | Associates an icon with an static control. |
| SetImage | Associates a new image with a static control. |
| SetText | Sets the text of a static control. |
Deletes a bitmap associated with a static control. Returns TRUE o FALSE.
FUNCTION DeleteBitmap (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.DeleteBitmap(hStatic)
Deletes a cursor associated with a static control. Returns TRUE or FALSE.
FUNCTION DeleteCursor (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.DeleteCursor(hStatic)
Deletes an enhanced metafile associated with a static control. Returns TRUE or FALSE.
FUNCTION DeleteEnhancedMetafile (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.DeleteEnhancedMetafile(hStatic)
Deletes an icon associated with a static control. Returns TRUE o FALSE.
FUNCTION DeleteIcon (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.DeleteIcon(hStatic)
Deletes an image associated with a static control. Returns TRUE or FALSE.
FUNCTION DeleteImage (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.DeleteImage(hStatic)
Disables the control. Returns False if the control was previous disabled; otherwise TRUE
FUNCTION Disable (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.Disable(hStatic)
Enables the control. Returns False if the control was previous enabled; otherwise TRUE
FUNCTION Enable (BYVAL hStatic AS HWND) AS BOOLEAN
CStatic.Enable(hStatic)
Retrieves a handle to the icon associated with a static control that has the SS_ICON style.
FUNCTION GetIcon (BYVAL hStatic AS HWND) AS HICON
DIM hIcon AS HICON = CStatic.GetIcon(hStatic)
Retrieves a handle to the image (icon or bitmap) associated with a static control. The return value is a handle to the image, if any; otherwise, it is NULL.
FUNCTION GetImage (BYVAL hStatic AS HWND) AS HICON
DIM hImage AS HANDLE = CStatic.GetIcon(hStatic)
Gets the text of a static control.
FUNCTION GetText (BYVAL hStatic AS HWND) AS DWSTRING
DIM dwsText AS DWSTRING = CStatic.GetText(hStatic)
Gets the length of the text of a static control.
FUNCTION GetTextLength (BYVAL hStatic AS HWND) AS LONG
DIM nLen AS LONG = CStatic.GetTextLength(hStatic)
Associates a bitmap with a static control. The return value is a handle to the image previously associated with the static control, if any; otherwise, it is NULL.
FUNCTION SetBitmap (BYVAL hStatic AS HWND, BYVAL hBmp AS HBITMAP) AS HBITMAP
| Parameter | Description |
|---|---|
| hBmp | Handle of the bitmap to set. |
DIM hOldBmp AS HBITMAP = CStatic.SetBitmap(hStatic, hBmp)
Associates a cursor with a static control. The return value is a handle to the cursor previously associated with the static control.
FUNCTION SetCursor (BYVAL hStatic AS HWND, BYVAL hCur AS HCURSOR) AS HCURSOR
| Parameter | Description |
|---|---|
| hCur | Handle of the cursor to set. |
DIM hOldCur AS HCURSOR = CStatic.SetCursor(hStatic, hCur)
Associates an enhanced metafile with a static control. The return value is a handle to the image previously associated with the static control, if any; otherwise, it is NULL.
FUNCTION SetEnhancedMetafile (BYVAL hStatic AS HWND, BYVAL hEMF AS HENHMETAFILE) AS HCURSOR
| Parameter | Description |
|---|---|
| hEMF | Handle of the enhanced metafile to set. |
DIM hOldEMF AS HENHMETAFILE = CStatic.SetCursor(hStatic, hEMF)
Associates an icon with an static control. The return value is a handle to the icon previously associated with the static control, if any; otherwise, it is NULL.
FUNCTION SetIcon (BYVAL hStatic AS HWND, BYVAL hIcon AS HICON) AS HICON
| Parameter | Description |
|---|---|
| hIcon | Handle of the icon to set. |
DIM hOldIcon AS HICON = CStatic.SetIcon(hStatic, hIcon)
Associates a new image with a static control. The return value is a handle to the image previously associated with the static control, if any; otherwise, it is NULL.
FUNCTION SetIcon (BYVAL hStatic AS HWND, BYVAL nType AS LONG, BYVAL hImage AS HANDLE) AS HANDLE
| Parameter | Description |
|---|---|
| hStatic | Handle of the static control. |
| nType | Type of the image to set. |
| hImage | Handle of the image to set. |
To associate an image with a static control, the control must have the proper style. The following table shows the style needed for each image type.
| Image type | Static control type |
|---|---|
| IMAGE_BITMAP | SS_BITMAP |
| IMAGE_CURSOR | SS_ICON |
| IMAGE_ENHMETAFILE | SS_ENHMETAFILE |
| IMAGE_ICON | SS_ICON |
DIM hOldBmp AS HICON = CStatic.SetImage(hStatic, IMAGE_BITMAP, hBmp)
DIM hOldIcon AS HICON = CStatic.SetImage(hStatic, IMAGE_ICON, hIcon)
DIM hOldCur AS HCURSOR = CStatic.SetImage(hStatic, IMAGE_CURSOR, hCur)
DIM hOldEMF AS HCURSOR = CStatic.SetImage(hStatic, IMAGE_ENHMETAFILE, hEMF)
Sets the text of a static control.
FUNCTION SetText (BYVAL hStatic AS HWND, BYVAL pwszText AS WSTRING PTR) AS BOOLEAN
| Parameter | Description |
|---|---|
| hStatic | Handle of the static control. |
| pwszText | The text to set. |
CStatic.SetText(hStatic, "New text")